﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Main
{
    public partial class Signup : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                txtName.Text = String.Empty;
                txtSurname.Text = String.Empty;
                txtCompany.Text = String.Empty;
                txtEmail.Text = String.Empty;
                txtPassword.Text = String.Empty;
                lblError.Text = String.Empty;
            }
        }

        protected void btnRegister_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtName.Text != String.Empty && txtSurname.Text != String.Empty && txtEmail.Text != String.Empty && txtCompany.Text != String.Empty && txtPassword.Text != String.Empty)
                {
                    ControlCommon common = new ControlCommon();
                    ControlUsers.Control control = new ControlUsers.Control();
                    String msg = control.RegisterUser(common.ConvertToEnglish(txtName.Text.Trim()), common.ConvertToEnglish(txtSurname.Text.Trim()), common.ConvertToEnglish(txtCompany.Text.Trim()), common.ConvertToEnglish(txtEmail.Text.Trim()), txtPassword.Text);

                    if (msg == String.Empty)
                    {
                        lblError.Text = "You have been successfully registered!";
                        txtName.Text = String.Empty;
                        txtSurname.Text = String.Empty;
                        txtCompany.Text = String.Empty;
                        txtEmail.Text = String.Empty;
                        txtPassword.Text = String.Empty;
                        Table3.Visible = true;
                    }
                    else
                        lblError.Text = msg;
                }
                else
                    lblError.Text = "Please give all the required information!";
            }
            catch (Exception ex)
            {
                lblError.Text = ex.ToString();
            }
        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect("Login.aspx");
        }

        protected void btnReset_Click(object sender, EventArgs e)
        {
            txtName.Text = String.Empty;
            txtSurname.Text = String.Empty;
            txtCompany.Text = String.Empty;
            txtEmail.Text = String.Empty;
            txtPassword.Text = String.Empty;
        }
    }
}